import mapper.DataMapper;
import observable.Observable;
import observable.ObservableCreate;
import observable.ObservableProxy;
import observable.emitter.Emitter;
import observable.emitter.ObservableOnSubscribe;
import observer.Observer;

public class Test {
    public static void main(String[] args) {
        new ObservableCreate<String>(new ObservableOnSubscribe<String>() {
            @Override
            public void subscribe(Emitter<String> emitter) {
                System.out.println("subscribe thread:" + Thread.currentThread());
                emitter.onNext("hello");
            }
        }).map(new DataMapper<String, Integer>() {

            @Override
            public Integer change(String s) {
                System.out.println("change thread:" + Thread.currentThread());
                return 123;
            }
        }).subscribeOnThread(true).observeOnThread(true).subscribe(new Observer<Integer>() {//对新的被观察者进行订阅
            @Override
            public void onNext(Integer obj) {
                System.out.println("onNext thread:" + Thread.currentThread());
                System.out.println(obj);
            }

            @Override
            public void onSubscribe() {
                System.out.println("onSubscribe");
            }

            @Override
            public void onError(Throwable throwable) {

            }

            @Override
            public void onComplete() {
                System.out.println("onComplete");
            }
        });

        //不使用转换
//        new ObservableCreate<String>(new ObservableOnSubscribe<String>() {
//            @Override
//            public void subscribe(Emitter<String> emitter) {
//                System.out.println("subscribe thread:" + Thread.currentThread());
//                emitter.onNext("hello");
//            }
//        }).subscribeOnThread(true).observeOnThread(true).subscribe(new Observer<String>() {
//            @Override
//            public void onNext(String obj) {
//                System.out.println("onNext thread:" + Thread.currentThread());
//                System.out.println(obj);
//            }
//
//            @Override
//            public void onSubscribe() {
//
//            }
//
//            @Override
//            public void onError(Throwable throwable) {
//
//            }
//
//            @Override
//            public void onComplete() {
//
//            }
//        });
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
